package cn.blue.org.controller;
import cn.blue.base.config.BussinessException;
import cn.blue.base.query.BaseQuery;
import cn.blue.base.util.AjaxResult;
import cn.blue.base.util.PageList;
import cn.blue.org.domain.Systemdictionarydetail;
import cn.blue.org.service.SystemdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/detail")
public class SystemdictionarydetailController {
    @Autowired
    private SystemdictionarydetailService systemdictionarydetailService;

    //字典类型查询多个明细  类型抽屉
    @RequestMapping("/list")
    public List<Systemdictionarydetail>findByDId(@RequestBody Systemdictionarydetail systemdictionarydetail){
        Long id = systemdictionarydetail.getId();
        return systemdictionarydetailService.findByDId(id);
    }

    //删除
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        if(id==null){
            throw new BussinessException("参数不能为空");
        }
        else {
            systemdictionarydetailService.del(id);
            return AjaxResult.me().setSuccess(true).setMsg("请求成功");
        }

    }

    //新增或者修改
    @ResponseBody
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarydetail systemdictionarydetail) {
        System.out.println(systemdictionarydetail);
        if (null == systemdictionarydetail.getId()) {
            systemdictionarydetailService.add(systemdictionarydetail);
        }else {
            systemdictionarydetailService.update(systemdictionarydetail);
        }
        return AjaxResult.me().setSuccess(true).setMsg("请求成功");


    }
    //分页查询
    @ResponseBody
    @RequestMapping
    public PageList<Systemdictionarydetail> queryPage(@RequestBody BaseQuery query){
        PageList<Systemdictionarydetail> list = systemdictionarydetailService.queryByPage(query);
        return list;


    }

    //批量删除
    @PatchMapping
    public AjaxResult batchDel(@RequestBody List<Long>ids){
        System.out.println(ids);
        systemdictionarydetailService.batchDel(ids);
        return AjaxResult.me().setSuccess(true).setMsg("删除成功");

    }

}
